/*
 * Created by Jaren at 2023/9/25 16:13
 */
import 'dart:typed_data';

import 'package:binary/binary.dart';
import 'package:inmotion_protocol/base/vehicle_data.dart';
import 'package:inmotion_protocol/common/mode.dart';

class EAllRealTimeInfo extends AllRealTimeData {
  EAllRealTimeInfo(ERealTimeInfo realTimeInfo, ERealTimeState realTimeState, ERealTimeError realTimeError) : super(realTimeInfo, realTimeState, realTimeError);
}

class ERealTimeInfo extends RealTimeInfo {
  @override
  int length() {
    return 0;
  }

  @override
  String toString() {
    return 'ERealTimeInfo{speed: ${speed.value}, batteryLevel: ${batteryLevel.value}';
  }
}

class ERealTimeState extends RealTimeState {
  @override
  int length() {
    return 0;
  }

  @override
  String toString() {
    return 'ERealTimeState{pcMode: ${pcMode.name}, locked: ${lockState.value}, headlight: ${headlightState.value}';
  }

  static Mode parseMode(Uint8ClampedList bytes, {int offset = 0}) {
    int mode = bytes[offset];
    switch (mode) {
      case 1:
      case 4: // 蓝牙遥控，认为为assisted
        return Mode.assisted;
      case 2:
        return Mode.working;
      case 3:
        return Mode.locked;
      case 0:
      default:
        return Mode.idle;
    }
  }
}

class ERealTimeError extends RealTimeError {
  Uint32 originalValue = Uint32.zero;

  @override
  int length() {
    return 0;
  }

  @override
  String toString() {
    return 'ERealTimeError{originalValue: $originalValue}';
  }

  bool hasVisibleWarningError() {
    return originalValue.value > 0;
  }
}
